import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;

public class NGuessNumber {
    
    public List<Integer> generateAnswer(){
        Random random = new Random();
        List<Integer> FourNum = new ArrayList<>();
        do{
            int num = random.nextInt(10);
            if(FourNum.indexOf(num) == -1){
                FourNum.add(num);
            }
        }while (FourNum.size() <= 3);
        return FourNum;
    }

    public List<Integer> getPlayerInput(){
        Scanner scanner = new Scanner(System.in);
        List<Integer> InputFourNum = new ArrayList<>();
        do{
           InputFourNum.add(scanner.nextInt());
        }while (InputFourNum.size() <= 3);
        return InputFourNum;
    }

    public int compareGuessAnswer( List<Integer> a ,  List<Integer> b){
        int t = 0;
        int f = 0;
        for (int i = 0; i < a.size(); i++) {
            if(a.get(i).equals(b.get(i))){
                t++;
            }else if(a.indexOf(b.get(i)) != -1){
                f++;
            }
        }
        System.out.println(String.format("a:%d,b:%d",t,f));
        return t;
    }


    public boolean isWin(int a){
        return a == 4;
    }



    public static void main(String[] args) {
        NGuessNumber nGuessNumber = new NGuessNumber();
        Scanner scanner = new Scanner(System.in);
        do{
            List<Integer> a = nGuessNumber.generateAnswer();

            System.out.println("答案:");
            System.out.println(a);


            int num = 0;
            while (true){
                System.out.println("依次输入四个答案:");
                List<Integer> b = nGuessNumber.getPlayerInput();
                int t = nGuessNumber.compareGuessAnswer(a,b);

                if(nGuessNumber.isWin(t)){
                    System.out.println(">>>游戏获胜<<<");
                    break;
                }

                if (num == 4){
                    System.out.println(">>>游戏五次机会用完了<<<");
                    break;
                }
                num++;

            }


            System.out.println("继续游戏输入y/n");

        }while (scanner.next().equals("y"));


    }
}
